namespace pal.SvnConf.Core
{
    public class AuthorizationEntry
    {
        private readonly string _securityPrincipalName;
        private readonly string _authorization;

        public AuthorizationEntry(string securityPrincipalName, string authorization)
        {
            _securityPrincipalName = securityPrincipalName.Trim();
            _authorization = authorization.Trim();
        }

        public string SecurityPrincipalName
        {
            get { return _securityPrincipalName; }
        }

        public string Authorization
        {
            get { return _authorization; }
        }

        public static AuthorizationEntry Parse(string line)
        {
            return new AuthorizationEntry(line.Split('=')[0], line.Split('=')[1]);
        }

        public override string ToString()
        {
            return string.Format("{0}\t= {1}", _securityPrincipalName, _authorization);
        }

        public override bool Equals(object other)
        {
            if (other == null || !(other is AuthorizationEntry)) return false;
            if (ReferenceEquals(this, other)) return true;
            if (_securityPrincipalName.Equals(((AuthorizationEntry) (other))._securityPrincipalName)
                && _authorization.Equals(((AuthorizationEntry) other)._authorization)) return true;
            return false;
        }
    }
}